package com.agw.crm.settings.service.impl;

import com.agw.crm.settings.dao.DicTypeDao;
import com.agw.crm.settings.dao.DicValueDao;
import com.agw.crm.settings.domain.DicType;
import com.agw.crm.settings.domain.DicValue;
import com.agw.crm.settings.service.DicService;
import com.agw.crm.utils.SqlSessionUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DicServiceImpl implements DicService {
    private DicTypeDao dicTypeDao = SqlSessionUtil.getSqlSession().getMapper(DicTypeDao.class);
    private DicValueDao dicValueDao = SqlSessionUtil.getSqlSession().getMapper(DicValueDao.class);

    @Override
    public Map<String, List<DicValue>> getAllCode() {
        Map<String, List<DicValue>> map = new HashMap<>();
        //首先获取到所有的字典类型
        List<DicType> dicTypeList = dicTypeDao.getDicTypeAll();
        //遍历类型，查询到每一个类型的所有值
        for (DicType dicType:dicTypeList){
            String code = dicType.getCode();
            List<DicValue> dicValue = dicValueDao.getDicValueAll(code);

            //将查询结果封装到Map集合中
            map.put(code,dicValue);
        }
        return map;
    }
}
